import request from '@/utils/request'
import axios from 'axios'

export function getDay(data) {
  return request({
    transformRequest: [
      function (data) {
        let ret = '';
        for (let it in data) {
          ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
        }
        return ret;
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    url: '/checkApi/getWorkDay',
    method: 'post',
    params: {},
    data: data
  })
}

export function Transformation(type) {
  if (type == "LEAVE_ANNUAL") {
    return '年休假'
  }else if(type == "LEAVE_BREASTFEEDING"){
    return '哺乳假'
  }else if(type == "LEAVE_COMPENSATED"){
    return '调休假'
  }else if(type == "LEAVE_CONTRACEPTION"){
    return '节育假'
  }else if(type == "LEAVE_FUNERAL"){
    return '丧假'
  }else if(type == "LEAVE_MARRIAGE"){
    return '婚假'
  }else if(type == "LEAVE_MATERNITY"){
    return '产假'
  }else if(type == "LEAVE_NURSING"){
    return '护理假'
  }else if(type == "LEAVE_PATERNITY"){
    return '陪产假'
  }else if(type == "LEAVE_PERSONAL"){
    return '事假'
  }else if(type == "LEAVE_VISIT_PARENT"){
    return '探亲假(父母)'
  }else if(type == "LEAVE_VISIT_SPOUSE"){
    return '探亲假(配偶)'
  }else if(type == "LEAVE_SICK"){
    return '病假'
  }
}

//预览pdf
export function browserPdf(id){

  // axios.get('/regulation/view/'+id)
  // .then(function (response) {
  //   console.log(response);
  //   if (navigator.userAgent.indexOf('Android') > -1) {
  //     //判断移动端是android 还是ios ，若是android 则要借助pdf插件
  //     window.location.href = this.url;
  //   } else {
  //     //ios直接打开pdf
  //     //window.location.href = url;
  //     window.location.href = this.url;
  //   }
  // })
  // .catch(function (error) {
  //   console.log(error);
  //   window.location.href = this.url;
  // })

  // var baseURL = window.sessionStorage.getItem('baseURL')
  // var baseURL =''
  //alert(baseURL)
  // axios.get( `${baseURL}/regulation/view/${id}`)
  //               .then(function (response) {
  //                   console.log(response);
                   
  //                       //ios直接打开pdf
  //                       //window.location.href = url;
  //                       window.location.href =  `/regulation/view/${id}`;
                    
  //               })
  //               .catch(function (error) {
  //                   console.log(error);
  //                  alert("文件出错")
  //               })

                axios({
                  headers: {
                      'Content-Type': 'application/x-www-form-urlencoded'
                  },
                  method: 'get',
                  url: `/regulation/view/${id}`,
              }).then(function (response) {
                console.log(response);
               
                    //ios直接打开pdf
                    //window.location.href = url;
                   window.location.href =  `${window.sessionStorage.getItem('baseURL')}/regulation/view/${id}`;
                
            })
            .catch(function (error) {
                console.log(error);
               alert("文件出错")
            })


  
                    
                      
                  
}


export function conversion(value) {
  var date = new Date(value * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    Y = date.getFullYear() + '-';
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();
    return Y+M+D+h+m+s;

  
}

